home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / STRINGS / TSTRINGS / HINTS.TXT < prev    next >
Text File  |  1991-12-10  |  2KB  |  70 lines

  1. Using Null Terminated Strings in Turbo Pascal 6
  2. ===============================================
  3.  
  4.  
  5.      Unlike Turbo Pascal for Windows the Turbo Pascal 6.0
  6. compiler does not have support for null terminated strings.
  7. Therefore there are some things which have to be stated
  8. differently. It must be said, though, that once you have made the
  9. described alterations the a program will still compile
  10. successfully under Turbo Pascal for Windows.
  11.  
  12.  
  13.      Included with the unit is a file called 'STRINGTE.PAS'. This
  14. demonstrates the use of the strings unit. This program can also
  15. be used along with the Turbo Pascal IDE Debugger to see that the
  16. strings unit is working correctly.
  17.  
  18. Syntax
  19. ======
  20.  
  21. Constant Null terminated strings. 
  22. --------------------------------
  23.  
  24. These are defined by
  25.  
  26. const
  27.  foostring : array [0..foolen] of char = 'FooText etc'#0;
  28.  
  29. They are referred to when passing then to functions by:
  30.  
  31.  @foostring[0]
  32.  
  33. This literally passes the address of the first character in the
  34. string to the function.
  35.  
  36.  
  37. Var type Null terminated strings.
  38. ---------------------------------
  39.  
  40. These are defined by
  41.  
  42. var
  43.  foovar : array [0..foolen] of char;
  44.  
  45. To blank one of these strings you could use:
  46.   foovar[0]:=#0;
  47.  
  48. or alternatively
  49.   Fillchar(foovar,Sizeof(foovar),#0);
  50.  
  51. Dynamic type Null terminated Strings.
  52. ====================================
  53.  
  54. These are defined by
  55.      var 
  56.       foodynamic : pChar;
  57.  
  58.  
  59. They are allocated on the heap using StrNew and Released by using
  60. StrDispose. You must use StrDispose to release memory allocated
  61. with StrNew. Since StrNew also keeps a check on the length of
  62. string allocated so always the correct amount is released even if
  63. a null is introduced into the middle of the string.
  64.  
  65. To refer to a specific character in a null terminated string you
  66. must use:
  67.  
  68. ptChar(foodynamic)^[foocharno]
  69.  
  70.